function check_b4_submit() {
	var effect = $("input[name='effect']:checked").val();
	var expire = $("input[name='expire']:checked").val();
	var s1 = $("input[name='effect_date']").val();
	var s2 = $("input[name='expire_date']").val();
	
	if(effect==="1" && empty(s1)) {
		alert("您尚未设置生效日期！！！");
		return false;
	}
	
	if(expire==="1" && empty(s2)) {
		alert("您尚未设置失效日期！！！");
		return false;
	}
	
	if(effect==="1" && expire==="1") {
		var effect_date = Date.parse(s1.replace(/-/g, "/"));
		var expire_date =Date.parse(s2.replace(/-/g, "/"));
		if(effect_date>=expire_date) {
			alert("失效时间不能小于生效时间！！！");
			return false;
		}
	}
	
	return true;
}

function reserve(type) {
	setvisible(type+'_date_label',type+'_date_div');
	enable(type+"_date");
}

function concel_resv(type) {
	setinvisible(type+'_date_label',type+'_date_div');
	disable(type+"_date");
}

function sub_persist() {
	if(!check_b4_submit()) return;

	var user_rule_type = $("input[name='user_rule_type']").val();
	var rule_type = $("input[name='rule_type']").val();
	var ef = 0;
	if(empty(user_rule_type)) persist(1);
	else if(user_rule_type!==rule_type) {
		$('#confirm_div').dialog("open");
	} else {
		persist(0);
	}
	
}

function persist(ef) {
	var rule_type = $("input[name='rule_type']").val();
	var start_time = $("input[name='effect_date']").val();
	var end_time = $("input[name='expire_date']").val();
	
	if(empty(start_time)) start_time = "2000-01-01 00:00:00";
	if(empty(end_time)) end_time = "9999-12-31 23:59:59";
	
	var  rowid = $("#style_list_table").getGridParam( "selrow" ); 
	if (rowid === null) return;
    var ret = $("#style_list_table").jqGrid("getRowData", rowid);
    var params = {
		"settings.TEMPLET_STYLE_ID":ret.TEMPLET_STYLE_ID,
		"settings.TEMPLET_ID":ret.TEMPLET_ID,
		"settings.WELCOME":ret.WELCOME,
		"settings.SKIN_ID":ret.SKIN_ID,
		"settings.IS_WEATHER":ret.IS_WEATHER,
		"settings.TITLE":$('input[name=title]').val(),
     	"settings.NUM_PER_TR":$("input[name='num_per_tr']:checked").val(),
		"settings.RULE_TYPE":rule_type,
		"settings.START_TEMP":$("input[name='start_temp']").val(),
		"settings.END_TEMP":$("input[name='end_temp']").val(),
		"settings.NUM_PER_LINE":$("input[name='num_per_tr']:checked").val(),
		"settings.TITLE":$("input[name='title']").val(),
		"settings.S_TIME":"2013-01-01 "+$("input[name='start_time']").val(),
		"settings.E_TIME":"2013-01-01 "+$("input[name='end_time']").val(),
		"settings.START_TIME":start_time,
		"settings.END_TIME":end_time,
		"settings.AREA_IDS":getCheckboxValues("area"),
		"ef":ef,
		"itemJsonStr":buildItemJsonStr()
	}
	
    $.post("persist.action", params, function(data,status) {
		if(Number(data.result.code)<0){
		    alert(data.result.msg);
		}else{
		   	alert("操作已成功！！！");
		  	window.location.href="user_rules.action";
		}
    }, "json");
}

